/************************************
 * Package: RGcpp					*
 * Authors: Rui Eduardo Gouveia Gil	*
 * Date: 2010						*
 ************************************/
#ifndef __RGCPP_SERVERUNIXSOCKET_H__
#define __RGCPP_SERVERUNIXSOCKET_H__

#ifndef _WIN32
#include <string>
#include <fstream>
#include <errno.h>
#include <string.h>
#include <sys/un.h>
#include <iostream>
#include <string.h>
#include <sys/socket.h>
#include <boost/thread/mutex.hpp>

#include "rgcpp/net/sockets/UnixSocket.h"
#include "rgcpp/exceptions/RuntimeException.h"

namespace rgcpp
{

#define DEFAULT_SERVER_SOCKET_DEPTH 128

class UnixServerSocket
{
	protected:
		int socketAccept;
		boost::mutex mut;
		bool releaseForced;
		unsigned int depth;
		std::string socketPath;

	public:
		UnixServerSocket(std::string socketPath);
		UnixServerSocket(std::string socketPath, std::string user, std::string group);
		~UnixServerSocket();

		UnixSocket* accept();
		void release();

		void setDepth(unsigned int value);
		unsigned int getDepth();

	private:
		int getUserId(std::string& user);
		int getGroupId(std::string& group);
};

}
#endif

#endif
